Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sitemaps #576

Merged
merged 1 commit into from
Oct 15, 2024
Merged

feat: sitemaps #576

merged 1 commit into from
Oct 15, 2024

Conversation

alexgoff
Copy link
Contributor

Resolves #563

Adds a sitemap index and a sitemap for each locale. Unfortunately the built-in sitemap API in Next.js does not support a sitemap index, or extending the sitemap for News or Image formats.

Given these limitations, the sitemaps are instead generated with two route handlers and an XML parsing library.

Includes Cypress test that validates the sitemap endpoints are generating valid XML

@alexgoff alexgoff added the feature Something new! label Oct 15, 2024
@alexgoff alexgoff self-assigned this Oct 15, 2024
today.getTime() - 1000 * 60 * 60 * 24 * 2
);

const newsData = news.map(({ uri, dateUpdated, title, date }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse news posts separately, if they are less than 2 days old then Google News markup is added to indicate new news release

import { generateSitemapUrl } from "@/lib/api/sitemap";
import { languages } from "@/lib/i18n/settings";

export async function GET() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this static endpoint generates a sitemap index for each locale

}
`;

const { data } = await queryAPI({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sitemap data is tagged as global so it is revalidated any time a page saves

@alexgoff alexgoff merged commit c16f3fb into develop Oct 15, 2024
4 checks passed
alexgoff added a commit that referenced this pull request Oct 15, 2024
alexgoff added a commit that referenced this pull request Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Something new!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant